$(function() {
	FastClick.attach(document.body);
});

var statisticsProjectVue = new Vue({
	el: "body",
	data: {
		otherFileList: [],
		noData: false,
		statrYear: "",
		startWeek: "",
		endYear: "",
		endWeek: "",
		jiYaData: "",
		zouFangData: ""
	},
	methods: {
		jiYa: function() {
			$(".statistics-other-list").addClass("hidden")
			$(".loader").removeClass("hidden")
			$(".statistics-other-title").removeClass("hidden")
			searchJiyaTotal(_this)
		},
		back: function() {
			window.history.go(-1); //返回上一页
		},
		guanXian: function() {
			$(".statistics-other-list").addClass("hidden")
			$(".loader").removeClass("hidden")
			$(".statistics-other-title").removeClass("hidden")
			searchGuanXianTotal(_this)
		},
		qiTa: function() {
			$(".statistics-other-list").addClass("hidden")
			$(".loader").removeClass("hidden")
			$(".statistics-other-title").removeClass("hidden")
			searchQiTaTotal(_this)
			_this.$nextTick(function() {
				setTimeout(function() {
					$(".statistics-other-list").removeClass("hidden")
					$(".loader").addClass("hidden")
				}, 200)
			})
		}
	},
	created: function() {
		_this = this //防止出现闭包
		_this.startYear = getUrlItem("startYear")
		_this.startWeek = getUrlItem("startWeek")
		_this.endYear = getUrlItem("endYear")
		_this.endWeek = getUrlItem("endWeek")
	},
	ready: function() {
		$(".statistics-other-title .tab>div").each(function(i) {
			$(".statistics-other-title .tab>div").eq(i).click(function() {
				$(".statistics-other-title .tab div").removeClass("active")
				$(this).addClass("active")
				$(".statistics-other-list>div").addClass("hidden")
				$(".statistics-other-list>div").eq(i).removeClass("hidden")
			})
		})
		//顶部tab切换

		$(function() {
			setFullScreen(".statistics-other-item", 60) //图表背景充满全屏
			var type = getUrlItem("type");
			if(type == "zoufang") {
				$(".statistics-other-title .tab>div").eq(1).click()
			}
			if(type == "jiya") {
				$(".statistics-other-title .tab>div").eq(0).click()
			}
			if(type == "qita") {
				$(".statistics-other-title .tab>div").eq(2).click()
			}
		})
	}
})


function searchJiyaTotal(a) {
	$.ajax({
		type: "post",
		url: "http://47.92.116.158:8099/BhGgjAPI/TempStatic.asmx/getTONGJI_TGCJY_Static?callback=?",
		data: {
			"year": a.startYear,
			"week": a.startWeek,
			"year2": a.endYear,
			"week2": a.endWeek
		},
		dataType: "json",
		success: function(jsondata) {
			console.log(jsondata)
			a.jiYaData = jsondata
			var sum = jsondata.TargetTotal
			var readySum = jsondata.BeginAmount
			var weekSum = jsondata.Amount
			$(".statistics-other-list").removeClass("hidden")
			$(".loader").addClass("hidden")

			if(sum == 0) {
				_this.noData = true
			} else {
				var readyRate = (readySum / sum).toFixed(2) * 100 + "%"
				var readyRate2 = ((readySum - weekSum) / sum).toFixed(2) * 100 + "%"

				var weekRate = (weekSum / sum).toFixed(2) * 100 + "%"
				$("#jiYa .progress-part-first").animate({ width: readyRate2 }, 500);
				$("#jiYa .progress-part-second").animate({ width: weekRate }, 500);
				$("#jiYa .progress-part-first").html(readyRate);
				if(weekRate == 0 + "%") {

				} else {
					$("#jiYa .progress-part-second").html(weekRate);
				}
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {}
	});
}

//管线单位数据接口
function searchGuanXianTotal(a) {
	$.ajax({
		type: "post",
		url: "http://47.92.116.158:8099/BhGgjAPI/TempStatic.asmx/getTONGJI_TDWZF_Static?callback=?",
		data: {
			"year": a.startYear,
			"week": a.startWeek,
			"year2": a.endYear,
			"week2": a.endWeek
		},
		dataType: "json",
		success: function(jsondata) {
			console.log(jsondata)
			a.zouFangData = jsondata
			var sum = jsondata.TargetTotal
			var readySum = jsondata.BeginAmount
			var weekSum = jsondata.Amount
			$(".statistics-other-list").removeClass("hidden")
			$(".loader").addClass("hidden")
			if(sum == 0) {
				_this.noData = true
			} else {
				var readyRate = (readySum / sum).toFixed(2) * 100 + "%"
				var readyRate2 = ((readySum - weekSum) / sum).toFixed(2) * 100 + "%"
				var weekRate = (weekSum / sum).toFixed(2) * 100 + "%"

				$("#guanXian .progress-part-first").animate({ width: readyRate2 }, 500);
				$("#guanXian .progress-part-second").animate({ width: weekRate }, 500);
				$("#guanXian .progress-part-first").html(readyRate);
				if(weekRate == 0 + "%") {

				} else {
					$("#guanXian .progress-part-second").html(weekRate);
				}
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {}
	});
}

//其他档案数据接口
function searchQiTaTotal(a) {
	$.ajax({
		type: "post",
		url: "http://47.92.116.158:8099/BhGgjAPI/TempStatic.asmx/getTONGJI_TDAN_Static2?callback=?",
		data: {
			"year": a.startYear,
			"week": a.startWeek,
			"year2": a.endYear,
			"week2": a.endWeek
		},
		dataType: "json",
		success: function(jsondata) {
			a.otherFileList = jsondata
			if(a.otherFileList.length == 0) {
				a.noData = true
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {}
	});
}

//用到的方法
function getUrlItem(name) { //id
	var url = location.search
	start = url.indexOf(name + "=")
	if(start != -1) {
		start = start + name.length + 1
		end = url.indexOf("&", start)
		if(end == -1) {
			end = url.length
			return unescape(url.substring(start, end))
		}
		return unescape(url.substring(start, end))
	}
	return '';
}

function setFullScreen(Name, Height) {
	$(document).ready(function() { //DOM加载后就执行
		var WindowHeight = $(window).height();
		$(Name).css('height', WindowHeight - Height);
	});
	$(window).resize(function() { //改变窗体大小时     *resize()变化或者改变事件
		var WindowHeight = $(window).height();
		$(Name).css('height', WindowHeight - Height);
	});
	$(window).scroll(function() { //浏览器有滚动条时的操作   scroll()滚动事件
		var WindowHeight = $(window).height();
		$(Name).css('height', WindowHeight - Height);
	});
}